package com.xuxin.queue.activity;

import android.Manifest;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.PermissionUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.xuxin.queue.R;
import com.xuxin.queue.base.BaseActivity;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import butterknife.BindView;

public class SplashActivity extends BaseActivity {
    @BindView(R.id.splash_image)
    ImageView splash_image;

    @Override
    public void setContentView() {
        setContentView(R.layout.activity_splash);
    }

    @Override
    public void initView() {
    }

    @Override
    public void initData() {
        permissions();
    }

    @Override
    public void onComplete() {
    }

    @Override
    public void onClick(View view) {
    }

    private final Handler mHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(@NotNull Message message) {
            if (message.what == 0) {
                ActivityUtils.startActivity(ConfigureActivity.class);
                finish();
            }
            return false;
        }
    });

    /**
     * 申请读写权限
     */
    public String[] permission = new String[]{
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_PHONE_STATE};

    private void permissions() {
        PermissionUtils.permissionGroup(permission).callback(new PermissionUtils.FullCallback() {
            @Override
            public void onGranted(@NonNull List<String> granted) {
                mHandler.sendEmptyMessageDelayed(0, 1000);
            }

            @Override
            public void onDenied(@NonNull List<String> deniedForever, @NonNull List<String> denied) {
                ToastUtils.showShort("权限已被拒绝，请打开权限");
                finish();
            }
        }).request();
    }
}